package com.gongzhiyun.springboot3test.controller;

import com.gongzhiyun.springboot3test.base.PageBean;
import com.gongzhiyun.springboot3test.base.R;
import com.gongzhiyun.springboot3test.service.TbMessageService;
import com.gongzhiyun.springboot3test.validate.CommonValidate;
import com.gongzhiyun.springboot3test.vo.ParamsDel;
import com.gongzhiyun.springboot3test.vo.ParamsDetailMessageData;
import com.gongzhiyun.springboot3test.vo.ParamsQueryMessage;
import com.gongzhiyun.springboot3test.vo.QueryMessageData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/message")
@Tag(name = "留言板相关功能")
public class TbMessageController {
    private final TbMessageService tbMessageService;

    @Operation(summary = "添加留言",description = "添加留言")
    @PostMapping("/add")
    public R<String> add(@RequestBody @Validated(CommonValidate.add.class) ParamsQueryMessage message) {
        return tbMessageService.addMessage(message);
    }

    @Operation(summary = "查询留言",description = "查询留言")
    @GetMapping("/query/{pn}/{ps}/{order}")
    public R<List<QueryMessageData>> query(ParamsQueryMessage message, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps, @PathVariable("order") Integer order) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        pageBean.setOrder(order);
        return tbMessageService.queryMessage(message, pageBean);
    }

    @Operation(summary = "查询用户留言",description = "查询留言")
    @GetMapping("/queryByUid/{uid}/{pn}/{ps}/{order}")
    public R<List<QueryMessageData>> queryByUid(@PathVariable("uid") Integer uid, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps, @PathVariable("order") Integer order) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        pageBean.setOrder(order);
        return tbMessageService.queryMessageByUid(uid, pageBean);
    }

    @Operation(summary = "点赞留言",description = "点赞留言")
    @GetMapping("/praise/{mid}")
    public R<String> praise(@PathVariable("mid") Integer mid) {
        return tbMessageService.praise(mid);
    }

    @Operation(summary = "删除留言",description = "删除留言")
    @PostMapping("/delete")
    public R<String> delete(@RequestBody ParamsDel del) {
        return tbMessageService.delete(del);
    }

    @Operation(summary = "查询留言详情",description = "查询留言详情")
    @GetMapping("/detail/{mid}/{pn}/{ps}/{order}")
    public R<ParamsDetailMessageData> detail(@PathVariable("mid") Integer mid, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps, @PathVariable("order") Integer order) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        pageBean.setOrder(order);
        return tbMessageService.detailMessage(mid, pageBean);
    }
}
